package IHM;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import Moteur.Observable;
import Moteur.Observer;

public class Molette extends JSlider implements Observable {

	public List<Observer> listeObserver;
	public List<Integer> listeFiltreMolette;

	//Quand on modifie la valeur de la molette on update les autres (notifyAllObservers)
	public Molette(){
		super(1,100,1);
		this.setMinimum(1);
		this.setBounds(10, 11, 183, 43);
		
		listeObserver = new ArrayList<Observer>(); 
		listeFiltreMolette = new ArrayList<>();

		this.setOrientation(JSlider.HORIZONTAL);
		this.setPaintTicks(true);
		this.setPaintLabels(true);
		//this.setValue(value);
		//this.setMajorTickSpacing(59);
		
		this.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				notifyObserver();
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	public List<Observer> getListeObserver() {
		return listeObserver;
	}


	public void setListeObserver(List<Observer> listeObserver) {
		this.listeObserver = listeObserver;
	}

	@Override
	public void add(Observer observer) {
		listeObserver.add(observer);
		notifyObserver();
	}

	@Override
	public void delete(Observer observer) {
		listeObserver.remove(observer);
	}

	@Override
	public void notifyObserver() {
		for(int i = 0; i < listeObserver.size() ; i++){
			listeObserver.get(i).updateMolette(this.getValue());
		}
	}

	@Override
	public void notifyObserver(Integer valeur) {
		// TODO Auto-generated method stub
	}


}
